package com.fw.ui.bao;

import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.fw.service.bean.EntryBean;
import com.fw.service.bean.SearchCriteriaBean;
import com.fw.service.bean.SearchResultBean;
import com.fw.service.merchantuser.MerchantUserService;
import com.fw.service.merchantuser.bean.MerchantUserBean;
import com.fw.service.merchantuser.bean.SearchMerchantUserBean;
import com.fw.ui.service.ServiceExecutor;
import com.fw.ui.service.ServiceOrder;

@Component
@Scope(SCOPE_PROTOTYPE)
public class MerchantUserBAO extends AbstractBAO implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Autowired
    private MerchantUserService merchantUserService;

    @SuppressWarnings("unchecked")
    public Map<String, Serializable> createMerchantUser(MerchantUserBean merchantUserBean) throws Exception {
	try {
	    ServiceOrder serviceOrder = new ServiceOrder();
	    serviceOrder.setServiceClass(this.merchantUserService);
	    serviceOrder.setMethodName("createMerchantUser");
	    serviceOrder.setParameterTypes(new Class[] { MerchantUserBean.class });
	    serviceOrder.setParameterValues(new Object[] { merchantUserBean });

	    ServiceExecutor serviceExecutor = new ServiceExecutor(serviceOrder, timeout);
	    serviceOrder = serviceExecutor.callService();
	    if (serviceOrder.getResultCode() != null && serviceOrder.getResultCode().equals(new Integer(0))) {
		List<EntryBean<String, Serializable>> entryBeans = (List<EntryBean<String, Serializable>>) serviceOrder.getReturnValue();
		if (entryBeans != null) {
		    Map<String, Serializable> map = new HashMap<String, Serializable>();
		    for (EntryBean<String, Serializable> entryBean : entryBeans) {
			map.put(entryBean.getKey(), entryBean.getValue());
		    }
		    return map;
		}
	    }
	} catch (Exception e) {
	    throw e;
	}
	return null;
    }

    public MerchantUserBean getMerchantUser(Long id) throws Exception {
	try {
	    ServiceOrder serviceOrder = new ServiceOrder();
	    serviceOrder.setServiceClass(this.merchantUserService);
	    serviceOrder.setMethodName("getMerchantUser");
	    serviceOrder.setParameterTypes(new Class[] { Long.class });
	    serviceOrder.setParameterValues(new Object[] { id });

	    ServiceExecutor serviceExecutor = new ServiceExecutor(serviceOrder, timeout);
	    serviceOrder = serviceExecutor.callService();
	    if (serviceOrder.getResultCode() != null && serviceOrder.getResultCode().equals(new Integer(0))) {
		MerchantUserBean result = (MerchantUserBean) serviceOrder.getReturnValue();
		return result;
	    }
	} catch (Exception e) {
	    throw e;
	}
	return null;
    }

    @SuppressWarnings("unchecked")
    public Map<String, Serializable> updateMerchantUser(MerchantUserBean merchantUserBean) throws Exception {
	try {
	    ServiceOrder serviceOrder = new ServiceOrder();
	    serviceOrder.setServiceClass(this.merchantUserService);
	    serviceOrder.setMethodName("updateMerchantUser");
	    serviceOrder.setParameterTypes(new Class[] { MerchantUserBean.class });
	    serviceOrder.setParameterValues(new Object[] { merchantUserBean });

	    ServiceExecutor serviceExecutor = new ServiceExecutor(serviceOrder, timeout);
	    serviceOrder = serviceExecutor.callService();
	    if (serviceOrder.getResultCode() != null && serviceOrder.getResultCode().equals(new Integer(0))) {
		List<EntryBean<String, Serializable>> entryBeans = (List<EntryBean<String, Serializable>>) serviceOrder.getReturnValue();
		if (entryBeans != null) {
		    Map<String, Serializable> map = new HashMap<String, Serializable>();
		    for (EntryBean<String, Serializable> entryBean : entryBeans) {
			map.put(entryBean.getKey(), entryBean.getValue());
		    }
		    return map;
		}
	    }
	} catch (Exception e) {
	    throw e;
	}
	return null;
    }

    @SuppressWarnings("unchecked")
    public Map<String, Serializable> deleteMerchantUser(MerchantUserBean merchantUserBean) throws Exception {
	try {
	    ServiceOrder serviceOrder = new ServiceOrder();
	    serviceOrder.setServiceClass(this.merchantUserService);
	    serviceOrder.setMethodName("deleteMerchantUser");
	    serviceOrder.setParameterTypes(new Class[] { MerchantUserBean.class });
	    serviceOrder.setParameterValues(new Object[] { merchantUserBean });

	    ServiceExecutor serviceExecutor = new ServiceExecutor(serviceOrder, timeout);
	    serviceOrder = serviceExecutor.callService();
	    if (serviceOrder.getResultCode() != null && serviceOrder.getResultCode().equals(new Integer(0))) {
		List<EntryBean<String, Serializable>> entryBeans = (List<EntryBean<String, Serializable>>) serviceOrder.getReturnValue();
		if (entryBeans != null) {
		    Map<String, Serializable> map = new HashMap<String, Serializable>();
		    for (EntryBean<String, Serializable> entryBean : entryBeans) {
			map.put(entryBean.getKey(), entryBean.getValue());
		    }
		    return map;
		}
	    }
	} catch (Exception e) {
	    throw e;
	}
	return null;
    }

    public Boolean checkUniqueUsername(String username) throws Exception {
	try {
	    ServiceOrder serviceOrder = new ServiceOrder();
	    serviceOrder.setServiceClass(this.merchantUserService);
	    serviceOrder.setMethodName("checkUniqueUsername");
	    serviceOrder.setParameterTypes(new Class[] { String.class });
	    serviceOrder.setParameterValues(new Object[] { username });

	    ServiceExecutor serviceExecutor = new ServiceExecutor(serviceOrder, timeout);
	    serviceOrder = serviceExecutor.callService();
	    if (serviceOrder.getResultCode() != null && serviceOrder.getResultCode().equals(new Integer(0))) {
		Boolean result = (Boolean) serviceOrder.getReturnValue();
		return result;
	    }
	} catch (Exception e) {
	    throw e;
	}
	return null;
    }

    @SuppressWarnings("unchecked")
    public List<MerchantUserBean> selectAllMerchantUser() throws Exception {
	try {
	    ServiceOrder serviceOrder = new ServiceOrder();
	    serviceOrder.setServiceClass(this.merchantUserService);
	    serviceOrder.setMethodName("selectAllMerchantUser");
	    serviceOrder.setParameterTypes(new Class[] {});
	    serviceOrder.setParameterValues(new Object[] {});

	    ServiceExecutor serviceExecutor = new ServiceExecutor(serviceOrder, timeout);
	    serviceOrder = serviceExecutor.callService();
	    if (serviceOrder.getResultCode() != null && serviceOrder.getResultCode().equals(new Integer(0))) {
		List<MerchantUserBean> result = (List<MerchantUserBean>) serviceOrder.getReturnValue();
		return result;
	    }
	} catch (Exception e) {
	    throw e;
	}
	return null;
    }

    @SuppressWarnings("unchecked")
    public SearchResultBean<MerchantUserBean> selectMerchantUser(SearchCriteriaBean<SearchMerchantUserBean> searchCriteriaBean)
	    throws Exception {
	try {
	    ServiceOrder serviceOrder = new ServiceOrder();
	    serviceOrder.setServiceClass(this.merchantUserService);
	    serviceOrder.setMethodName("selectMerchantUser");
	    serviceOrder.setParameterTypes(new Class[] { SearchCriteriaBean.class });
	    serviceOrder.setParameterValues(new Object[] { searchCriteriaBean });

	    ServiceExecutor serviceExecutor = new ServiceExecutor(serviceOrder, timeout);
	    serviceOrder = serviceExecutor.callService();
	    if (serviceOrder.getResultCode() != null && serviceOrder.getResultCode().equals(new Integer(0))) {
		SearchResultBean<MerchantUserBean> result = (SearchResultBean<MerchantUserBean>) serviceOrder.getReturnValue();
		return result;
	    }
	} catch (Exception e) {
	    throw e;
	}
	return null;
    }

    @SuppressWarnings("unchecked")
    public Map<String, Serializable> resetPasswordMerchantUser(MerchantUserBean merchantUserBean) throws Exception {
	try {
	    ServiceOrder serviceOrder = new ServiceOrder();
	    serviceOrder.setServiceClass(this.merchantUserService);
	    serviceOrder.setMethodName("resetPasswordMerchantUser");
	    serviceOrder.setParameterTypes(new Class[] { MerchantUserBean.class });
	    serviceOrder.setParameterValues(new Object[] { merchantUserBean });

	    ServiceExecutor serviceExecutor = new ServiceExecutor(serviceOrder, timeout);
	    serviceOrder = serviceExecutor.callService();
	    if (serviceOrder.getResultCode() != null && serviceOrder.getResultCode().equals(new Integer(0))) {
		List<EntryBean<String, Serializable>> entryBeans = (List<EntryBean<String, Serializable>>) serviceOrder.getReturnValue();
		if (entryBeans != null) {
		    Map<String, Serializable> map = new HashMap<String, Serializable>();
		    for (EntryBean<String, Serializable> entryBean : entryBeans) {
			map.put(entryBean.getKey(), entryBean.getValue());
		    }
		    return map;
		}
	    }
	} catch (Exception e) {
	    throw e;
	}
	return null;
    }

}
